# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

# at this point its only php who wants this for imap support
# if more packages needs the c-client lib we might want to
# build it shared
pkgname=imap
pkgver=2007f
pkgrel=15
pkgdesc="An IMAP/POP server"
url="http://www.washington.edu/imap"
arch="all"
license="Apache-2.0"
subpackages="$pkgname-dev c-client:cclient"
makedepends="openssl-dev>3"
source="http://ftp.ntua.gr/pub/net/mail/imap/imap-$pkgver.tar.gz
	fix-linking.patch
	c-client-2006k_KOLAB_Annotations.patch
	1006_openssl1.1_autoverify.patch
	2014_openssl1.1.1_sni.patch
	"
options="!check"

prepare() {
	default_prepare
	sed -e "s:-g -fno-omit-frame-pointer -O6:\${CFLAGS}:" \
		-e "s:SSLDIR=/usr/local/ssl:SSLDIR=/usr:" \
		-e "s:SSLCERTS=\$(SSLDIR)/certs:SSLCERTS=/etc/ssl/certs:" \
		-e "s:^CC=.*:CC=${CC:-cc}:" \
		-i src/osdep/unix/Makefile
}

build() {
	export GCCCFLAGS="$CFLAGS"
	yes "y" | make -j1 slx SPECIALAUTHENTICATORS=ssl SSLTYPE=unix \
		EXTRACFLAGS="$CFLAGS -fPIC" \
		EXTRALDFLAGS="$LDFLAGS"
}

package() {
	mkdir -p $pkgdir/usr/sbin
	install -D -m755 imapd/imapd $pkgdir/usr/sbin/imapd
	install -D -m755 ipopd/ipop2d $pkgdir/usr/sbin/ipop2d
	install -D -m755 ipopd/ipop3d $pkgdir/usr/sbin/ipop3d
	for i in c-client mail imap4r1 rfc822 linkage misc smtp nntp osdep \
			env_unix env fs ftl nl tcp sslio utf8 utf8aux; do
		install -D -m644 c-client/$i.h \
			"$pkgdir"/usr/include/imap/$i.h
	done
	install -m644 c-client/linkage.c "$pkgdir"/usr/include/imap/linkage.c

	install -Dm755 c-client/libc-client.so.1.0.0 \
		"$pkgdir"/usr/lib/libc-client.so.1.0.0
	ln -s libc-client.so.1.0.0 "$pkgdir"/usr/lib/libc-client.so.1
	ln -s libc-client.so.1.0.0 "$pkgdir"/usr/lib/libc-client.so
}

cclient() {
	pkgdesc="UW IMAP c-client library"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/
}

sha512sums="7c3e1d9927872001e768ff2ddbcf3af74078243efe58dd70e01d966856b7611134e4b579818691a954bade9acaeeda6f2f30f40d812b8aa20990de5cb90d5d35  imap-2007f.tar.gz
f8a4b5b8759b690273ec8c86db55c3c3ebf7b358321aa829341bc65e98db0f10696b1eeae922eecada668f011b0b3231ed73c3a959b47b4cba00568bf7d231c1  fix-linking.patch
871093236b3ae300968e1e200a2389566af72ed1f62ad57c1dc617dd59e8378f29175fe07e5cfc575e022f3c27769b06850cbf21567f7cc359ca204c4d87a3af  c-client-2006k_KOLAB_Annotations.patch
7ecbe52adc6e3d1deee05790745642f794150ffaebf51c0cf689dc036eea9c7d80e643648aac37bf0aa83ac138b8bb63abfad3b540bc9440de3456162dfabae5  1006_openssl1.1_autoverify.patch
884fe866cdce7955134c0ff939f1f5ef151ccbed772e64807095d369cb96fb67790cb070a7ea588e1e8f5523fcfeac5a6af6b1db69ec8f516b4c08db0cb029cb  2014_openssl1.1.1_sni.patch"
